using System.Collections;

namespace CSharpPro._1014;

public class Demo
{
    public void TestPrint()
    {
        string[] arr2 = new string[3];
        arr2[0] = "aa";
        arr2[1] = "bb";
        Console.WriteLine(arr2[2]);
        
        string[] arr3 = {"aaa" , "bbb" ,"ccc"};
        Console.WriteLine(arr3[0]);
        Console.WriteLine(arr3[1]);
        
        //二维数组
        int[,] arr4 = new int[2,3];
        int[,] arr5 = {{1,2,3},{4,5,6},{7,8,9}};
        Console.WriteLine(arr5[1,1]);
        
        int[] arr6 = {11,7,88,23,99,9};
        Array.Sort(arr6);
        Array.Reverse(arr6);
        Console.WriteLine();
        for(int i=0;i<arr6.Length;i++)
        {
            Console.Write(arr6[i] + "\t");
        }
        Console.WriteLine();
        //var 
        foreach (int i in arr6)
        {
            Console.Write(i + "\t");
        }
        
        //.var
        ArrayList list = new ArrayList();
        list.Add(1);
        list.Add(2);
        list.Add(3);
        Console.WriteLine(list.Count);
        foreach (int i in list)
        {
            Console.Write(i + "\t");
        }
        Hashtable hashtable = new Hashtable();
        hashtable.Add("1", 1);
        hashtable.Add("2", "aaaaa");
        hashtable.Add("3",list);
        hashtable.Add("4", arr6);
        Console.WriteLine(hashtable["1"]);
    }
    public void TestPrint2()
    {
        double[] numbers = { 3.5, 1.2, 4.8, 2.3 };
        Sort(numbers);

        foreach (var n in numbers)
        {
            Console.WriteLine(n);
        }
    }
    private static void Sort(double[] a)
    {
        double temp;
        for (int i = 0; i < a.Length - 1; i++)
        {
            for (int j = 0; j < a.Length - i - 1; j++)
            {
                if (a[j] < a[j + 1]) // 降序
                {
                    temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
    }
}